// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import Router from 'vue-router'
import VueResource from 'vue-resource'
import index from "./pages/index"
import HelloWorld from "./components/HelloWorld"
import campaign from "./pages/campaign"
import datamanage from "./pages/datamanage"//数据管理
import box from "./pages/box"
import comment from "./pages/comment"
import phonemanage from "./pages/phonemanage"//电催管理
import visitmanage from "./pages/visitmanage"//外访管理
import login from "./pages/login"//登录
import assistmanage from "./pages/assistmanage"//协催管理
import head from "./components/head"//协催管理

import litigationmanage from "./pages/litigationmanage"//诉讼管理
import statistics from "./pages/statistics"//统计报表
import works from "./pages/works"//协同办公
import staff from "./pages/staff"//员工管理
import system from "./pages/system"//系统管理
import { Tabbar, TabbarItem, Swiper, SwiperItem, Group, Cell, Rater, Masker } from 'vux';
Vue.component('Tabbar', Tabbar);
Vue.component('Swiper', Swiper);
Vue.component('TabbarItem', TabbarItem);
Vue.component('SwiperItem', SwiperItem);
Vue.component('Group', Group);
Vue.component('Cell', Cell);
Vue.component('Rater', Rater);
Vue.component('Masker', Masker);
Vue.use(Router)
Vue.use(VueResource)
Vue.config.productionTip = false
var router = new Router({
	routes: [{
			path: '/index',
			component: index,
      meta:{
        requireAuth: true // 配置此条，进入页面前判断是否需要登陆
      },
			children: [
			  {
					path: '/HelloWorld',
					name: 'HelloWorld',
					component: HelloWorld
				}

			]
		},
		{
			path: '/campaign',
			component: campaign,
		},
    {
      path: '/datamanage',//数据管理
      name:datamanage,
      component: datamanage,
    },
    {
      path: '/head',//头部
      name:head,
      component: head,
    },
    {
      path: '/login',//登录
      name:login,
      component: login,
    },
    {
      path: '/phonemanage',//电催管理
      name:phonemanage,
      component: phonemanage,
    },
    {
      path: '/visitmanage',//外访管理
      name:visitmanage,
      component: visitmanage,
    },
    {
      path: '/assistmanage',//协催管理
      name:assistmanage,
      component: assistmanage,
    },
    {
      path: '/litigationmanage',//诉讼管理
      name:litigationmanage,
      component: litigationmanage,
    },
    {
      path: '/statistics',//统计报表
      name:statistics,
      component: statistics,
    },
    {
      path: '/works',//协同办公
      name:works,
      component: works,
    },
    {
      path: '/staff',//员工管理
      name:staff,
      component: staff,
    },
    {
      path: '/system',//系统管理
      name:system,
      component: system,
    },
		{
			path: '/box',
			component: box,
		},
		{
			path: '/comment',
			component: comment,
		},

	],
	mode: "history"
});


router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
    if (localStorage.getItem('username')) { // 查询本地存储信息是否已经登陆
      next();
    } else {
      next({
        path: '/login', // 未登录则跳转至login页面
        query: {redirect: to.fullPath} // 登陆成功后回到当前页面，这里传值给login页面，to.fullPath为当前点击的页面
      });
    }
  } else {
    next();
  }
});

router.push("/index");

export default router;
/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
